import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store";

Vue.use(VueRouter)
import errorRouter from '@/views/errorpage/router'


const routes = [
  {
    path:'/',
    redirect:'/guide'
  },
  {
    path:'/guide',
    name:'guide',
    component:()=>import('@/views/guide/guide.vue')
  },
  {
    path:'/main',
    name:'main',
    component:()=>import('@/views/main/main.vue'),
    redirect:'/main/find',
    children:[
      {
        path:'find',
        name:'find',
        component:()=>import('@/views/find/find.vue'),
      },
      {
        path:'radio',
        name:'radio',
        component:()=>import('@/views/radio/radio.vue'),
      },
      {
        path:'singer',
        name:'singer',
        component:()=>import('@/views/singer/singer.vue'),
      },
    ]
  },
  {
    path:'/login',
    name:'login',
    component:()=>import('@/views/logins/login.vue')
  },
  {
    path:'/register',
    name:'register',
    component:()=>import('@/views/logins/register.vue')
  },
  {
    path:'/peeling',
    name:'peeling',
    component:()=>import('@/views/myself/peeling.vue')
  },
  {
    path:'/search',
    name:'search',
    component:()=>import('@/views/search/search.vue')
  },
  {
    path:'/recommend',
    name:'recommend',
    component:()=>import('@/views/recommend/recommend.vue')
  },
  {
    path:'/allrecommend',
    name:'allrecommend',
    component:()=>import('@/views/recommend/allrecommend.vue')
  },
  {
    path:'/singerinfo',
    name:'singerinfo',
    component:()=>import('@/views/singer/singerinfo.vue')
  },
  ...errorRouter,
  {
    path:'*',
    redirect:'/main/find'
  }
]


const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})


router.beforeEach((to,from,next)=>{
  if(from.name == 'login' || from.name == 'register' || from.name=='guide'){
    store.commit('setFootPlayer',true);
  }else if((from.name == 'find'||from.name == 'radio'||from.name == 'mine'||from.name == 'singer') && (to.name != 'find'&&to.name != 'radio'&&to.name != 'mine'&&to.name != 'singer')){
    store.commit('setPlayerBtm','0');
  }else if(to.name == 'login' || to.name == 'register' || to.name=='guide'){
    store.commit('setTimer',clearInterval(store.state.timer));
  }
  next()
})



export default router
